import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;


public class Section extends JPanel implements ActionListener {
	
	private SystemEssentials gui = new SystemEssentials(2);
	private JButton bClassList, bSec;
	private JCheckBox cView[] = new JCheckBox[5];
	private JComboBox cbFilterBy, cbStatus;
	public String[] sFilterBy = {"---", "Status", "Position", "Area", "Sections Handled"};
	public String[] sStatus = {"---", "Active", "Grades"};
	
	private ImageIcon iClassList = new ImageIcon("gui/buttons/bClassList.png"),
					  iClassList_ = new ImageIcon("gui/buttons/bClassList_.png"),
	  				  iSec = new ImageIcon("gui/buttons/bSec.png"),
	  				  iSec_ = new ImageIcon("gui/buttons/bSec_.png");
	
	public Section(){
		setLayout(null);
		setBounds(0,0,700,600);	
		setOpaque(false);

		refreshTable();
		createGui();		
	}
	
	public void createGui(){
		for(int i=0; i<5; i++){
			cView[i] = new JCheckBox();
			cView[i].addActionListener(this);
			cView[i].setSelected(true);
			switch(i){
			case 0: cView[i].setText("ID"); break;
			case 1: cView[i].setText("Status"); break;
			case 2: cView[i].setText("Year Level"); break;
			case 3: cView[i].setText("Section Name"); break;
			case 4: cView[i].setText("Adviser"); break;
			}
			cView[i].setBounds(25,440+(i*19),140,19);
			if(i==5)
				cView[5].setVisible(false);
			add(cView[i]);
		}
		
		cbFilterBy = new JComboBox(sFilterBy);
		cbFilterBy.setBounds(170,440,190,30);
		cbFilterBy.addActionListener(this);
		add(cbFilterBy);
		
		cbStatus = new JComboBox(sStatus);
		cbStatus.setBounds(170,480,190,30);
		add(cbStatus);
		
		bSec = new JButton(iSec);
		bSec.setBounds(600,105,75,18);
		bSec.setRolloverIcon(iSec_);
		bSec.setBorderPainted(false);
		bSec.setContentAreaFilled(false);
		bSec.setVisible(true);
		bSec.addActionListener(this);
		add(bSec);
		
		bClassList = new JButton(iClassList);
		bClassList.setBounds(506,105,86,18);
		bClassList.setRolloverIcon(iClassList_);
		bClassList.setBorderPainted(false);
		bClassList.setContentAreaFilled(false);
		bClassList.setVisible(true);
		bClassList.addActionListener(this);
		add(bClassList);
		
		add(gui);		
	}
		
	public void actionPerformed(ActionEvent a) {
		if(a.getSource() == bClassList){
			MainPanel.goToPage(4);
		}
		else if(a.getSource() == bSec){
			MainPanel.goToPage(3);
		}
	}
		
	public void refreshTable(){
		gui.resetTableModel(2);
		// for input data from sql
		for(int i=0; i<1; i++){
			Vector<String> rowData = new Vector<String>();
			//sample
			rowData.add("001");
			rowData.add("Active");
			rowData.add("Third Year");
			rowData.add("Perseverance");
			rowData.add("Edzel Gonzales");
			//sample
			gui.model.addRow(rowData);
		}

		for(int i=0; i<gui.model.getColumnCount(); i++){
			gui.table.getColumnModel().getColumn(i).setCellRenderer(gui.cellRenderer);
			gui.setColumnWidth(i,1);
		}
		
		for(int i=0; i<1; i++){
			Vector<String> rowData = new Vector<String>();
			//sample
			rowData.add("002");
			rowData.add("Active");
			rowData.add("Fourth Year");
			rowData.add("Piety");
			rowData.add("Marvin De Pano");
			//sample
			gui.model.addRow(rowData);
		}

		for(int i=0; i<gui.model.getColumnCount(); i++){
			gui.table.getColumnModel().getColumn(i).setCellRenderer(gui.cellRenderer);
			gui.setColumnWidth(i,1);
		}
	}
		
	public void refreshGUI(){
		refreshTable();
		gui.refreshGUI();
	}
}
